package com.caipiao.controller;

import com.caipiao.mapper.SPlanMapper;
import com.caipiao.pojo.ObjectResult;
import com.caipiao.pojo.SPlan;
import com.caipiao.pojo.XMLBean;
import com.caipiao.service.PlanService;
import com.caipiao.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2019/1/7.
 */
@Controller
@RequestMapping("/plan")
public class PlanController {

    @Autowired
    private PlanService planService;
    @Autowired
    private SPlanMapper sPlanMapper;

    /**
     * 赛事
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/index",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult index(XMLBean xmlBean){
        return   planService.index(xmlBean);
    }

    /**
     * 赛事详情
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/plan",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult plan(XMLBean xmlBean){
        return planService.matchDetails(xmlBean);
    }

    /**
     * 方案详情
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/details",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult details(XMLBean xmlBean){
        return planService.planDetails(xmlBean);
    }

    /**
     * 购买方案
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/buy",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult buy(XMLBean xmlBean){
        if(StringUtil.isEmpty(xmlBean.getToken())) return ObjectResult.build("0","未登录");
        return planService.planBuy(xmlBean);
    }

    /**
     * 连续跟投
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/with",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult with(XMLBean xmlBean){
        if(StringUtil.isEmpty(xmlBean.getToken())) return ObjectResult.build("0","未登录");
        return ObjectResult.build("0","该功能尚未开通，敬请期待");
//        return planService.planWith(xmlBean);
    }

    /**
     * 连续跟单记录查询
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/planWith",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult planWith(XMLBean xmlBean){
        if(StringUtil.isEmpty(xmlBean.getToken())) return ObjectResult.build("0","未登录");
        return planService.selectPlanWith(xmlBean);
    }

    /**
     * 跟单详情
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/planWithDetais",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult planWithDetais(XMLBean xmlBean){
        if(StringUtil.isEmpty(xmlBean.getToken())) return ObjectResult.build("0","未登录");
        List<SPlan> list = sPlanMapper.selectplanByPlanWithId(xmlBean.getId());
        for (int i=1;i<=list.size();i++){
            list.get(i-1).setCount("第"+i+"轮");
        }
        return ObjectResult.build("1","成功",list);
    }


    /**
     * 连续跟单取消
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/cancelPlanWith",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult cancelPlanWith(XMLBean xmlBean){
        if(StringUtil.isEmpty(xmlBean.getToken())) return ObjectResult.build("0","未登录");
        return planService.cancelPlanWith(xmlBean);
    }

}
